package util

import (
	"gopkg.in/yaml.v3"
	"log"
	"os"
)

type Server struct {
	Host string `yaml:"host"`
	Port string `yaml:"port"`
}
type Database struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	DBName   string `yaml:"DBName"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}
type Redis struct {
	Host string `yaml:"host"`
	Port string `yaml:"port"`
}

type Config struct {
	Server
	Database
	Redis
}

func GetConfig() (*Config, error) {
	data, err := os.ReadFile("./config/config.yaml")
	if err != nil {
		log.Printf("无法读取文件%v", err)
		panic(err)
		return nil, err
	}
	var config Config
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		log.Printf("解析配置文件失败：%v", err)
		panic(err)
		return nil, err
	}
	return &config, nil
}
